package com.zw.chat.controller;

import com.zw.chat.common.domain.AjaxResult;
import com.zw.chat.domain.ChatSession;
import com.zw.chat.service.IChatSessionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author by: zyl
 * @ClassName: ChatSessionController
 * @Description: 会话控制器
 * @Date: 2024/12/5 10:27
 */
@RestController
@CrossOrigin
@RequestMapping("/chat/session")
public class ChatSessionController {

    @Resource
    private IChatSessionService chatSessionService;

    @PostMapping
    public AjaxResult saveOrUpdateChatSession(@RequestBody ChatSession session) {
        return AjaxResult.success(chatSessionService.saveOrUpdateChatSession(session));
    }

    @GetMapping("/query")
    public AjaxResult queryChatSession(@RequestParam("userId") String userId) {
        return AjaxResult.success(chatSessionService.queryChatSession(userId));
    }

    @GetMapping("/{sessionId}")
    public AjaxResult getChatSession(@PathVariable String sessionId) {
        return AjaxResult.success(chatSessionService.findChatSessionById(sessionId));
    }

    @DeleteMapping("/{sessionId}")
    public AjaxResult deleteChatSession(@PathVariable String sessionId) {
        chatSessionService.deleteChatSessionById(sessionId);
        return AjaxResult.success();
    }
}
